package com.butang.controller;

import com.butang.pojo.Result;
import com.butang.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * ClassName: UploadController
 * Package: com.butang.controller
 * Description:
 *
 * @Author BuTang
 * @Create 2023/7/13 17:21
 * @Version 1.0
 */
@Slf4j
@RestController
@Controller
public class UploadController {

@Autowired
    AliOSSUtils ali ;
    @PostMapping("/upload")
    public Result upload(String username, String name, MultipartFile image) throws IOException {
        log.info("文件上传：{},{},{}",username,name,image);


        String upload = ali.upload(image);

//        String originalFilename = image.getOriginalFilename();

//
//        String oldname = originalFilename.substring(originalFilename.lastIndexOf("."));
//        String newname = UUID.randomUUID().toString()+oldname;
//
//        image.transferTo(new File("D:/develop/image/"+newname));
        return Result.success(upload);
    }
}
